﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Text;
using MiWebSite_Core;
using WLMCoreLibrary;
using Newtonsoft.Json;


namespace MWS_AddDirectory.handlers.categorias
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType = "application/json";
            Response.Write(listaCategoriasJSON());
            Response.End();            
        }

        public string listaCategoriasJSON()
        {
            dbConnector ConexionDB = new dbConnector();
            string buscar = WLMFunctions.CleanQuery( Request.QueryString["tag"]);

            CategoriaCollection cats = new CategoriaCollection(buscar, ref ConexionDB);
            ConexionDB.CloseConnection();
            List<TagCat> categorias = new List<TagCat>();
            foreach (Categoria item in cats.Elementos)
            {
                categorias.Add(new TagCat(item.nombreCategoria, item.id.ToString()));
            }            
            return JsonConvert.SerializeObject(categorias);
        }
    }
}